package com.numberone.web.controller.typeList;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.numberone.common.base.AjaxResult;
import com.numberone.common.page.TableDataInfo;
import com.numberone.framework.web.base.BaseController;
import com.numberone.system.domain.Goods;
import com.numberone.system.qo.GoodsLikeQuery;
import com.numberone.system.service.IGoodsService;
import com.numberone.system.service.ITypeListService;
import com.numberone.system.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类目列表 信息操作处理
 *
 * @author 郭财源
 * @date 2020-09-25
 */
@Controller
@RequestMapping("/api/TypeList")
public class TypeListApiController extends BaseController {
    @Autowired
    private ITypeListService typeListService;
    @Autowired
    private IGoodsService goodsService;

    /**
     * 获取类目列表
     * @return
     */
    @ResponseBody
    @PostMapping("/getTypeList")
    public AjaxResult getTypeList()
    {
        TableDataInfo dataTable = getDataTable(typeListService.selectTypeList());
        return AjaxResult.success(null,dataTable);
    }

    /**
     * 获取类目相关商品
     * @param typeFirstId
     * @param typeThirdId
     * @param qo
     * @return
     */
    @ResponseBody
    @PostMapping("/getGoodsByType")
    public Object getGoodsByType(Long typeFirstId, Long typeThirdId, GoodsLikeQuery qo)
    {
        Goods goods = new Goods();
        goods.setTypethirdId(typeThirdId);
        goods.setTypeinfofristId(typeFirstId);
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Goods> goodsList = goodsService.selectGoodsList(goods);
        PageInfo<Goods> goodsPageInfo = new PageInfo<>(goodsList);
//        PageInfo pageInfo = goodsService.selectGoodsList(goods, qo);
//        if (pageInfo.getList().isEmpty()){
//            return JsonResult.noGoods();
//        }
        return JsonResult.success(goodsPageInfo);
    }
}
